{
 "metadata": {
  "name": "",
  "signature": "sha256:91cb49615ff73ea799022440811545d971f344925e863113d3a6e221eeb2e798"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Plotting and Visualization"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from numpy.random import randn\n",
      "import numpy as np\n",
      "import os\n",
      "import matplotlib.pyplot as plt\n",
      "np.random.seed(12345)\n",
      "plt.rc('figure', figsize=(10, 6))\n",
      "from pandas import Series, DataFrame\n",
      "import pandas as pd\n",
      "np.set_printoptions(precision=4)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "%matplotlib inline"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "%pwd"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "%cd ../book_scripts/"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "A brief matplotlib API primer"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import matplotlib.pyplot as plt"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Figures and Subplots"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig = plt.figure()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "ax1 = fig.add_subplot(2, 2, 1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "ax2 = fig.add_subplot(2, 2, 2)\n",
      "ax3 = fig.add_subplot(2, 2, 3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy.random import randn\n",
      "plt.plot(randn(50).cumsum(), 'k--')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "_ = ax1.hist(randn(100), bins=20, color='k', alpha=0.3)\n",
      "ax2.scatter(np.arange(30), np.arange(30) + 3 * randn(30))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.close('all')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig, axes = plt.subplots(2, 3)\n",
      "axes"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 4,
     "metadata": {},
     "source": [
      "Adjusting the spacing around subplots"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.subplots_adjust(left=None, bottom=None, right=None, top=None,\n",
      "                wspace=None, hspace=None)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig, axes = plt.subplots(2, 2, sharex=True, sharey=True)\n",
      "for i in range(2):\n",
      "    for j in range(2):\n",
      "        axes[i, j].hist(randn(500), bins=50, color='k', alpha=0.5)\n",
      "plt.subplots_adjust(wspace=0, hspace=0)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig, axes = plt.subplots(2, 2, sharex=True, sharey=True)\n",
      "for i in range(2):\n",
      "    for j in range(2):\n",
      "        axes[i, j].hist(randn(500), bins=50, color='k', alpha=0.5)\n",
      "plt.subplots_adjust(wspace=0, hspace=0)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Colors, markers, and line styles"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.figure()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.plot(randn(30).cumsum(), 'ko--')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.close('all')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data = randn(30).cumsum()\n",
      "plt.plot(data, 'k--', label='Default')\n",
      "plt.plot(data, 'k-', drawstyle='steps-post', label='steps-post')\n",
      "plt.legend(loc='best')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Ticks, labels, and legends"
     ]
    },
    {
     "cell_type": "heading",
     "level": 4,
     "metadata": {},
     "source": [
      "Setting the title, axis labels, ticks, and ticklabels"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig = plt.figure(); ax = fig.add_subplot(1, 1, 1)\n",
      "ax.plot(randn(1000).cumsum())\n",
      "\n",
      "ticks = ax.set_xticks([0, 250, 500, 750, 1000])\n",
      "labels = ax.set_xticklabels(['one', 'two', 'three', 'four', 'five'],\n",
      "                            rotation=30, fontsize='small')\n",
      "ax.set_title('My first matplotlib plot')\n",
      "ax.set_xlabel('Stages')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 4,
     "metadata": {},
     "source": [
      "Adding legends"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig = plt.figure(); ax = fig.add_subplot(1, 1, 1)\n",
      "ax.plot(randn(1000).cumsum(), 'k', label='one')\n",
      "ax.plot(randn(1000).cumsum(), 'k--', label='two')\n",
      "ax.plot(randn(1000).cumsum(), 'k.', label='three')\n",
      "\n",
      "ax.legend(loc='best')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Annotations and drawing on a subplot"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from datetime import datetime\n",
      "\n",
      "fig = plt.figure()\n",
      "ax = fig.add_subplot(1, 1, 1)\n",
      "\n",
      "data = pd.read_csv('ch08/spx.csv', index_col=0, parse_dates=True)\n",
      "spx = data['SPX']\n",
      "\n",
      "spx.plot(ax=ax, style='k-')\n",
      "\n",
      "crisis_data = [\n",
      "    (datetime(2007, 10, 11), 'Peak of bull market'),\n",
      "    (datetime(2008, 3, 12), 'Bear Stearns Fails'),\n",
      "    (datetime(2008, 9, 15), 'Lehman Bankruptcy')\n",
      "]\n",
      "\n",
      "for date, label in crisis_data:\n",
      "    ax.annotate(label, xy=(date, spx.asof(date) + 50),\n",
      "                xytext=(date, spx.asof(date) + 200),\n",
      "                arrowprops=dict(facecolor='black'),\n",
      "                horizontalalignment='left', verticalalignment='top')\n",
      "\n",
      "# Zoom in on 2007-2010\n",
      "ax.set_xlim(['1/1/2007', '1/1/2011'])\n",
      "ax.set_ylim([600, 1800])\n",
      "\n",
      "ax.set_title('Important dates in 2008-2009 financial crisis')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig = plt.figure()\n",
      "ax = fig.add_subplot(1, 1, 1)\n",
      "\n",
      "rect = plt.Rectangle((0.2, 0.75), 0.4, 0.15, color='k', alpha=0.3)\n",
      "circ = plt.Circle((0.7, 0.2), 0.15, color='b', alpha=0.3)\n",
      "pgon = plt.Polygon([[0.15, 0.15], [0.35, 0.4], [0.2, 0.6]],\n",
      "                   color='g', alpha=0.5)\n",
      "\n",
      "ax.add_patch(rect)\n",
      "ax.add_patch(circ)\n",
      "ax.add_patch(pgon)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Saving plots to file"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig.savefig('figpath.svg')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig.savefig('figpath.png', dpi=400, bbox_inches='tight')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from io import BytesIO\n",
      "buffer = BytesIO()\n",
      "plt.savefig(buffer)\n",
      "plot_data = buffer.getvalue()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "matplotlib configuration"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.rc('figure', figsize=(10, 10))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Plotting functions in pandas"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Line plots"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.close('all')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "s = Series(np.random.randn(10).cumsum(), index=np.arange(0, 100, 10))\n",
      "s.plot()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "df = DataFrame(np.random.randn(10, 4).cumsum(0),\n",
      "               columns=['A', 'B', 'C', 'D'],\n",
      "               index=np.arange(0, 100, 10))\n",
      "df.plot()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Bar plots"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig, axes = plt.subplots(2, 1)\n",
      "data = Series(np.random.rand(16), index=list('abcdefghijklmnop'))\n",
      "data.plot(kind='bar', ax=axes[0], color='k', alpha=0.7)\n",
      "data.plot(kind='barh', ax=axes[1], color='k', alpha=0.7)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "df = DataFrame(np.random.rand(6, 4),\n",
      "               index=['one', 'two', 'three', 'four', 'five', 'six'],\n",
      "               columns=pd.Index(['A', 'B', 'C', 'D'], name='Genus'))\n",
      "df\n",
      "df.plot(kind='bar')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.figure()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "df.plot(kind='barh', stacked=True, alpha=0.5)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "tips = pd.read_csv('ch08/tips.csv')\n",
      "party_counts = pd.crosstab(tips.day, tips.size)\n",
      "party_counts\n",
      "# Not many 1- and 6-person parties\n",
      "party_counts = party_counts.ix[:, 2:5]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Normalize to sum to 1\n",
      "party_pcts = party_counts.div(party_counts.sum(1).astype(float), axis=0)\n",
      "party_pcts\n",
      "\n",
      "party_pcts.plot(kind='bar', stacked=True)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Histograms and density plots"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.figure()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "tips['tip_pct'] = tips['tip'] / tips['total_bill']\n",
      "tips['tip_pct'].hist(bins=50)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.figure()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "tips['tip_pct'].plot(kind='kde')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.figure()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "comp1 = np.random.normal(0, 1, size=200)  # N(0, 1)\n",
      "comp2 = np.random.normal(10, 2, size=200)  # N(10, 4)\n",
      "values = Series(np.concatenate([comp1, comp2]))\n",
      "values.hist(bins=100, alpha=0.3, color='k', normed=True)\n",
      "values.plot(kind='kde', style='k--')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Scatter plots"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "macro = pd.read_csv('ch08/macrodata.csv')\n",
      "data = macro[['cpi', 'm1', 'tbilrate', 'unemp']]\n",
      "trans_data = np.log(data).diff().dropna()\n",
      "trans_data[-5:]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.figure()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.scatter(trans_data['m1'], trans_data['unemp'])\n",
      "plt.title('Changes in log %s vs. log %s' % ('m1', 'unemp'))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pd.scatter_matrix(trans_data, diagonal='kde', color='k', alpha=0.3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Plotting Maps: Visualizing Haiti Earthquake Crisis data"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data = pd.read_csv('ch08/Haiti.csv')\n",
      "data.info()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data[['INCIDENT DATE', 'LATITUDE', 'LONGITUDE']][:10]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data['CATEGORY'][:6]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.describe()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data = data[(data.LATITUDE > 18) & (data.LATITUDE < 20) &\n",
      "            (data.LONGITUDE > -75) & (data.LONGITUDE < -70)\n",
      "            & data.CATEGORY.notnull()]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def to_cat_list(catstr):\n",
      "    stripped = (x.strip() for x in catstr.split(','))\n",
      "    return [x for x in stripped if x]\n",
      "\n",
      "def get_all_categories(cat_series):\n",
      "    cat_sets = (set(to_cat_list(x)) for x in cat_series)\n",
      "    return sorted(set.union(*cat_sets))\n",
      "\n",
      "def get_english(cat):\n",
      "    code, names = cat.split('.')\n",
      "    if '|' in names:\n",
      "        names = names.split(' | ')[1]\n",
      "    return code, names.strip()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "get_english('2. Urgences logistiques | Vital Lines')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "all_cats = get_all_categories(data.CATEGORY)\n",
      "# Generator expression\n",
      "english_mapping = dict(get_english(x) for x in all_cats)\n",
      "english_mapping['2a']\n",
      "english_mapping['6c']"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def get_code(seq):\n",
      "    return [x.split('.')[0] for x in seq if x]\n",
      "\n",
      "all_codes = get_code(all_cats)\n",
      "code_index = pd.Index(np.unique(all_codes))\n",
      "dummy_frame = DataFrame(np.zeros((len(data), len(code_index))),\n",
      "                        index=data.index, columns=code_index)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "dummy_frame.ix[:, :6].info()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "for row, cat in zip(data.index, data.CATEGORY):\n",
      "    codes = get_code(to_cat_list(cat))\n",
      "    dummy_frame.ix[row, codes] = 1\n",
      "\n",
      "data = data.join(dummy_frame.add_prefix('category_'))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "data.ix[:, 10:15].info()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from mpl_toolkits.basemap import Basemap\n",
      "import matplotlib.pyplot as plt\n",
      "\n",
      "def basic_haiti_map(ax=None, lllat=17.25, urlat=20.25,\n",
      "                    lllon=-75, urlon=-71):\n",
      "    # create polar stereographic Basemap instance.\n",
      "    m = Basemap(ax=ax, projection='stere',\n",
      "                lon_0=(urlon + lllon) / 2,\n",
      "                lat_0=(urlat + lllat) / 2,\n",
      "                llcrnrlat=lllat, urcrnrlat=urlat,\n",
      "                llcrnrlon=lllon, urcrnrlon=urlon,\n",
      "                resolution='f')\n",
      "    # draw coastlines, state and country boundaries, edge of map.\n",
      "    m.drawcoastlines()\n",
      "    m.drawstates()\n",
      "    m.drawcountries()\n",
      "    return m"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 10))\n",
      "fig.subplots_adjust(hspace=0.05, wspace=0.05)\n",
      "\n",
      "to_plot = ['2a', '1', '3c', '7a']\n",
      "\n",
      "lllat=17.25; urlat=20.25; lllon=-75; urlon=-71\n",
      "\n",
      "for code, ax in zip(to_plot, axes.flat):\n",
      "    m = basic_haiti_map(ax, lllat=lllat, urlat=urlat,\n",
      "                        lllon=lllon, urlon=urlon)\n",
      "\n",
      "    cat_data = data[data['category_%s' % code] == 1]\n",
      "\n",
      "    # compute map proj coordinates.\n",
      "    x, y = m(cat_data.LONGITUDE.values, cat_data.LATITUDE.values)\n",
      "\n",
      "    m.plot(x, y, 'k.', alpha=0.5)\n",
      "    ax.set_title('%s: %s' % (code, english_mapping[code]))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(12, 10))\n",
      "fig.subplots_adjust(hspace=0.05, wspace=0.05)\n",
      "\n",
      "to_plot = ['2a', '1', '3c', '7a']\n",
      "\n",
      "lllat=17.25; urlat=20.25; lllon=-75; urlon=-71\n",
      "\n",
      "def make_plot():\n",
      "\n",
      "    for i, code in enumerate(to_plot):\n",
      "        cat_data = data[data['category_%s' % code] == 1]\n",
      "        lons, lats = cat_data.LONGITUDE, cat_data.LATITUDE\n",
      "\n",
      "        ax = axes.flat[i]\n",
      "        m = basic_haiti_map(ax, lllat=lllat, urlat=urlat,\n",
      "                            lllon=lllon, urlon=urlon)\n",
      "\n",
      "        # compute map proj coordinates.\n",
      "        x, y = m(lons.values, lats.values)\n",
      "\n",
      "        m.plot(x, y, 'k.', alpha=0.5)\n",
      "        ax.set_title('%s: %s' % (code, english_mapping[code]))\n",
      "        "
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "make_plot()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "shapefile_path = 'ch08/PortAuPrince_Roads/PortAuPrince_Roads'\n",
      "m.readshapefile(shapefile_path, 'roads')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}